import vnode from './vnode.js';
// 编写一个低配版本的h函数
export default function(sel, data, c) {
    // c : text / [] / h()
    if (arguments.length < 3) {
        throw new Error('缺少参数');
    }
    if (typeof c === 'string' || typeof c === 'number') {
        return vnode(sel, data, undefined, c, undefined);
    } else if (Array.isArray(c)) {
        let children = [];
        for (var i = 0; i < c.length; i++) {
            // 检查c[i]必须是一个对象
            if (typeof c[i] == 'object' && c[i].hasOwnProperty('sel')) {
                children.push(c[i]); //收集children
            } else {
                throw new Error('数组元素类型错误');
            }
        }
        return vnode(sel, data, children, undefined, undefined);
    } else if (typeof c === 'object' && c.hasOwnProperty('sel')) {
        let children = [c];
        return vnode(sel, data, children, undefined, undefined);
    } else {
        throw new Error('参数类型错误');
    }
}